package tower;

import java.awt.Image;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;

import creep.Creep;
import tower.maintower;
public class maintower implements towerdefencegame.constantsUsed{
	private int towerX, towerY, towerType;
	private int cost, upgradeCost, value, sellPrice,damage;
	private int lv = 1;
	private String name;
	int lol;
	int upgradeDamage;
	double  upgradeSpeed, range,upgradeRange, speed;
	private missile.Missile kanon;
	private double delay;
	private boolean isSelected;
	double Dps;
	double upgradeDps;
	
	public maintower(int y, int x, int towerType) {
				this.towerX = x;
				this.towerY = y;
				this.towerType = towerType;
				this.isSelected = false;
				if (towerType == TOWER_MOCCA) mocca(this.lv);
				else if (towerType == TOWER_MC) MC(lv);
				else if (towerType == TOWER_GENNIS) gennis(lv);
				else if (towerType == TOWER_SKRUF_ORIGINAL) skrufOrginal(this.lv);
				else if (towerType == TOWER_GENNIS_XSTERK) gennisXSterk(lv);
				else if (towerType == TOWER_SKRUF_XSTERK) skrufXSterk(lv);
				getSellPrice();
				this.kanon = null;
				this.delay = 0;
	}
	// ADDED FOR TESTING BY SINDRE :D
	public void setMissile(Image img,Creep creep, int cellSize) {
		
		this.kanon = new missile.Missile(this.speed,img,creep,this,this.damage, cellSize);
	}
	public void setSelected(boolean a) {
		this.isSelected = a;
	}
	public boolean getSelected() {
		return this.isSelected;
	}
	public missile.Missile getMissile() {
		return this.kanon;
	}
	public void setX(int x) {
		this.towerX = x;
	}
	public void setY(int y) {
		this.towerY = y;
	}
	
	public double getDelay(){
		return this.delay;
	}
	
	public void setDelay(double delay){
		this.delay= delay;
	}
	
	public void setDps(){
		this.Dps = damage/speed;
	}
	
	public void setUpgradeDps(){
		this.upgradeDps= upgradeDamage/upgradeSpeed;
	}
	
	public double getDps(){
		return this.Dps;
	}
	
	public double getUpgradeDps(){
		return this.upgradeDps;
	}
	//-----------------------------------
	
	
	public missile.Missile getKanon(){
		return this.kanon;
	}
	
	public int getDamage () {
		return damage;
	}
	public double getRange () {
		return range;
	}
	public int getLv () {
		return lv;
	}
	public double getSpeed () {
		return speed;
	}
	public int getPositionX () {
		return this.towerX;
	}
	public int getPositionY () {
		return this.towerY;
	}
	public int getSellPrice () {
		double sell = 0.75*value;
		sellPrice = (int)sell;
		return sellPrice;
	}
	public int getUpgradeCost () {
		return upgradeCost;
	}
	public int getCost () {
		return cost;
	}
	public int getTowerType () {
		return towerType;
	}
	public boolean canBuyUpgrade () {
		this.value += this.upgradeCost; 
		return true;
	}

	
	public String upgrade () {
		if (lv<10){
		this.value += this.upgradeCost; 
		this.lv += 1;
		String melding = "You bought a upgrade for: " +upgradeCost;
		choose(towerType, lv);
		getSellPrice();
		return melding;
		}
		else {
			String melding = "You dont have enough money";
			return melding;
		}
	
	}
	public String toString () {
		String tekst = "<html> Tower name: " + this.name + 
		"<br>Level: " + this.lv +
		"<br>Damage: " + this.damage + 
		"<br>Range: " + getRange()+ 
		"<br>Speed: " + getSpeed() +
		"<br>Value: " + value + 
		"<br>Sell Price: " +this.sellPrice + 
		"<br><b>Upgrade cost: " + getUpgradeCost() + "</html>";
		return tekst;
		
	}
	public void choose (int towerType, int lv){
		if (towerType == 1) mocca(lv);
		else if (towerType == 2) MC(lv);
		else if (towerType == 3) gennis(lv);
		else if (towerType == 4) skrufOrginal(lv);
		else if (towerType == 5) gennisXSterk(lv);
		else if (towerType == 6) skrufXSterk(lv);
	}
	public String updateToString (){
		if(lv<10){
		getUpgradeValues(towerType, lv+1);
		String tekst = "<html> Tower name: " + name + 
		"<br>Level: " + (this.lv+1) +
		"<br>Damage after upgrade: " + upgradeDamage + 
		"<br>Range after upgrade: " + upgradeRange+ 
		"<br>Speed after upgrade: " + upgradeSpeed + "</html>";
		getUpgradeValues(towerType, lv);
		return tekst;
		}
		else {
			return "<html> This Tower i fully UPGRADED </html>";
		}
		
	}
	public void getUpgradeValues (int towertype, int lv){
		 choose(towertype, lv);
		 upgradeDamage = getDamage();
		 upgradeRange = getRange();
		 upgradeSpeed = getSpeed();
	}
	public void skrufOrginal (int lv) {
		name = "Skruf Orginal";
		if(lv==1){
		this.damage = 10;
		this.cost = SKRUF_ORGINAL_COST;
		this.range = 50;
		this.value = cost;
		this.speed = 5;
		this.upgradeCost = 190;
		
		}
		else if (lv ==2){
			this.damage = 20;
			this.upgradeCost = 210;
			this.range = 60;
			this.speed = 6;
		}
		else if (lv==3){
			this.damage = 30;
			this.upgradeCost = 300;
			this.range = 90;
			this.speed = 7;
		}
		else if (lv==4){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
		else if (lv==5){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
		else if (lv==6){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
		else if (lv==7){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
		else if (lv==8){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
		else if (lv==9){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
		else if (lv>=10){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
		
	}
	public void skrufXSterk (int lv) {
		name = "Skruf X-tra Sterk";
		if(lv==1){
		this.damage = 50;
		this.cost = SKRUF_XSTERK_COST;
		this.range = 100;
		this.value = cost;
		this.speed = 4;
		this.upgradeCost = 800;
		}
		else if(lv==2){
			this.damage = 90;
			this.range = 120;
			this.speed = 5;
			this.upgradeCost = 1000;
			}
		else if (lv==3){
			this.damage = 30;
			this.upgradeCost = 300;
			this.range = 90;
			this.speed = 7;
		}
		else if (lv==4){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
		else if (lv==5){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
		else if (lv==6){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
		else if (lv==7){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
		else if (lv==8){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
		else if (lv==9){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
		else if (lv>=10){
			this.damage = 40;
			this.upgradeCost = 0;
			this.range = 100;
			this.speed = 8;
		}
	}
	public void gennis (int lv) {
		name = "General";
		if(lv==1){
		this.damage = 100;
		this.cost = GENNIS_COST;
		this.range = 10;
		this.value = cost;
		this.speed = 2;
		this.upgradeCost = 400;
		}
		else if(lv==2){
			this.damage = 200;
			this.range = 12;
			this.speed = 2;
			this.upgradeCost = 400;
			}
		else if (lv==3){
			this.damage = 300;
			this.upgradeCost = 500;
			this.range = 13;
			this.speed = 3;
		}
		else if (lv==4){
			this.damage = 400;
			this.upgradeCost = 700;
			this.range = 15;
			this.speed = 4;
		}
		else if (lv==5){
			this.damage = 600;
			this.upgradeCost = 0;
			this.range = 17;
			this.speed = 4.5;
		}
		else if (lv==6){
			this.damage = 600;
			this.upgradeCost = 0;
			this.range = 17;
			this.speed = 4.5;
		}
		else if (lv==7){
			this.damage = 600;
			this.upgradeCost = 0;
			this.range = 17;
			this.speed = 4.5;
		}
		else if (lv==8){
			this.damage = 600;
			this.upgradeCost = 0;
			this.range = 17;
			this.speed = 4.5;
		}
		else if (lv==9){
			this.damage = 600;
			this.upgradeCost = 0;
			this.range = 17;
			this.speed = 4.5;
		}
		else if (lv==10){
			this.damage = 600;
			this.upgradeCost = 0;
			this.range = 17;
			this.speed = 4.5;
		}
	}
	public void gennisXSterk (int lv) {
		name = "General Ekstra sterk";
		if(lv==1){
		this.damage = 1;
		this.cost = GENNIS_XSTERK_COST;
		this.range = 10;
		this.value = cost;
		this.speed = 10;
		this.upgradeCost = 100;
		}
		else if(lv==2){
			this.damage = 400;
			this.range = 55;
			this.speed = 9;
			this.upgradeCost = 200;
			}
		else if (lv==3){
			this.damage = 500;
			this.upgradeCost = 300;
			this.range = 60;
			this.speed = 9;
		}
		else if (lv==4){
			this.damage = 600;
			this.upgradeCost = 400;
			this.range = 65;
			this.speed = 9;
		}
		else if (lv==5){
			this.damage = 700;
			this.upgradeCost = 500;
			this.range = 70;
			this.speed = 9;
		}
		else if (lv==6){
			this.damage = 800;
			this.upgradeCost = 600;
			this.range = 75;
			this.speed = 9;
		}
		else if (lv==7){
			this.damage = 900;
			this.upgradeCost = 700;
			this.range = 80;
			this.speed = 9;
		}
		else if (lv==8){
			this.damage = 1000;
			this.upgradeCost = 800;
			this.range = 85;
			this.speed = 9;
		}
		else if (lv==9){
			this.damage = 1100;
			this.upgradeCost = 900;
			this.range = 90;
			this.speed = 9;
		}
		else if (lv>=10){
			this.damage = 1200;
			this.upgradeCost = 1000;
			this.range = 100;
			this.speed = 20;
		}
		
	}
	public void MC (int lv) {
		name = "Monte Cristo";
		if(lv==1){
		this.damage = 30;
		this.cost = MC_COST;
		this.range = 3.5;
		this.value = cost;
		this.speed = 4;
		this.upgradeCost = 120;
		}
		else if(lv==2){
			this.damage = 35;
			this.range = 4.5;
			this.speed = 5;
			this.upgradeCost = 200;
			}
		else if (lv==3){
			this.damage = 40;
			this.upgradeCost = 300;
			this.range = 5;
			this.speed = 6;
		}
		else if (lv==4){
			this.damage = 50;
			this.upgradeCost = 500;
			this.range = 7;
			this.speed = 9;
		}
		else if (lv==5){
			this.damage = 90;
			this.upgradeCost = 0;
			this.range = 10;
			this.speed = 9;
		}
		else if (lv==6){
			this.damage = 90;
			this.upgradeCost = 0;
			this.range = 10;
			this.speed = 9;
		}
		else if (lv==7){
			this.damage = 90;
			this.upgradeCost = 0;
			this.range = 10;
			this.speed = 9;
		}
		else if (lv==8){
			this.damage = 90;
			this.upgradeCost = 0;
			this.range = 10;
			this.speed = 9;
		}
		else if (lv==9){
			this.damage = 90;
			this.upgradeCost = 0;
			this.range = 10;
			this.speed = 9;
		}
		else if (lv==10){
			this.damage = 90;
			this.upgradeCost = 0;
			this.range = 10;
			this.speed = 9;
		}
	}
	public void mocca (int lv) {
		name = "Mocca";
		if(lv==1){
		this.damage = 20;
		this.cost = MOCCA_COST;
		this.range = 3;
		this.value = cost;
		this.speed = 3.5;
		this.upgradeCost = 90;
		}
		else if(lv==2){
			this.damage = 30;
			this.range = 4;
			this.speed = 3.9;
			this.upgradeCost = 90;
			}
		else if (lv==3){
			this.damage = 30;
			this.upgradeCost = 120;
			this.range = 4.5;
			this.speed = 4.5;
		}
		else if (lv==4){
			this.damage = 50;
			this.upgradeCost = 200;
			this.range = 5;
			this.speed = 4.5;
		}
		else if (lv==5){
			this.damage = 80;
			this.upgradeCost = 0;
			this.range = 6;
			this.speed = 5;
		}
		else if (lv==6){
			this.damage = 80;
			this.upgradeCost = 0;
			this.range = 6;
			this.speed = 5;
		}
		else if (lv==7){
			this.damage = 80;
			this.upgradeCost = 0;
			this.range = 6;
			this.speed = 5;
		}
		else if (lv==8){
			this.damage = 80;
			this.upgradeCost = 0;
			this.range = 6;
			this.speed = 5;
		}
		else if (lv==9){
			this.damage = 80;
			this.upgradeCost = 0;
			this.range = 6;
			this.speed = 5;
		}
		else if (lv==10){
			this.damage = 80;
			this.upgradeCost = 0;
			this.range = 6;
			this.speed = 5;
		}
	}
	
	public Shape getShape(int cellSize){
		return new Ellipse2D.Double(this.getPositionX()-(this.range*cellSize/2)+cellSize/2, this.getPositionY()-(this.range*cellSize/2)+cellSize/2, (double)((this.range/1)*cellSize),(double)((this.range/1)*cellSize));
	}

	
	

}
